<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
	<title>123</title>
	<script src="./jquery.js"></script>
</head>
<body>
123123
</body>
</html>
<script type="text/javascript">
$(function(){
var json = '[{"pv": 61, "aste": "0", "vdes": "0", "time": "2016-08-09 11:21:59", "ciid": "123.2.1", "type": "A", "qul": "0"},{"pv": 62, "aste": "0", "vdes": "0", "time": "2016-08-09 11:21:59", "ciid": "123.2.2", "type": "A", "qul": "0"},{"pv": 63, "aste": "0", "vdes": "0", "time": "2016-08-09 11:21:59", "ciid": "123.2.3", "type": "A", "qul": "0"},{"pv": 64, "aste": "0", "vdes": "0", "time": "2016-08-09 11:21:59", "ciid": "123.2.4", "type": "A", "qul": "0"},{"pv": 65, "aste": "0", "vdes": "0", "time": "2016-08-09 11:21:59", "ciid": "123.2.5", "type": "A", "qul": "0"},{"pv": 66, "aste": "0", "vdes": "0", "time": "2016-08-09 11:21:59", "ciid": "123.2.6", "type": "A", "qul": "0"},{"pv": 67, "aste": "0", "vdes": "0", "time": "2016-08-09 11:21:59", "ciid": "123.2.7", "type": "A", "qul": "0"},{"pv": 68, "aste": "0", "vdes": "0", "time": "2016-08-09 11:21:59", "ciid": "123.2.8", "type": "A", "qul": "0"}]';
 alert(json_data(json));
});





function  json_data(json){
var date = new Array();
var arrjson = $.parseJSON(json);
var data = [];

date = get_date(json);
 for(var i=0 ;i<date.length; i++){
 	var tmp ={};
 	//debugger;
 	//data.push($.myTime.UnixToDate(date[i],true,8));
 	tmp.date = $.myTime.UnixToDate(date[i],true,8);
 	var v= 1;
 	for(var j=0;j<arrjson.length;j++){
 		if(date[i] == $.myTime.DateToUnix(arrjson[j]['time']) ){//匹配json中的时间是否与date中的时间相同，如果相同就将json中的ciid添加到数组中
 		   //tmp.push(arrjson[j]['time']);
        /*    tmp['ciid'+v]= arrjson[j]['ciid'];*/
        id= arrjson[j]['pv'];
           tmp[id]= arrjson[j]['ciid'];
           v++ ;
 		}
 	}
 	data.push(tmp);

 }
 //console.log(data);
return JSON.stringify(data);

}
//将json中的日期去重排序从小到大
function get_date(json){
		var arrjson = $.parseJSON(json);
		var timearr = new Array();
		var datearr = new Array();
		var timea = new Array();
		//console.log(arrjson);
		//去出时间进行排序（从小到大）
		 for(var i=0 ;i<arrjson.length; i++){

		timearr.push(arrjson[i]['time']);
		 }
		array1=undulpicate(timearr);
		/*alert(timearr.sort(sortNumber));*/
	
		for(var j=0 ;j<array1.length; j++){
			var time=$.myTime.DateToUnix(array1[j]);
		     datearr.push(time);
		    
		}
		datearr = datearr.sort(sortNumber);
/*		for(var n=0 ;n<datearr.length; n++){
			var date=$.myTime.UnixToDate(datearr[n],true,8);
		     timea.push(date);
		    
		}*/
		return datearr;
}

//去重函数	
function undulpicate(array){
	for(var i=0;i<array.length;i++) {
		for(var j=i+1;j<array.length;j++) {
			//注意 ===
			if(array[i]===array[j]) {
				array.splice(j,1);
				j--;
			}
		}
	}
	return array;
}

//时间排序
function sortNumber(a, b)
{
    return a - b
}

//日期与时间戳转换
(function($) {
  $.extend({
    myTime: {
      /**
       * 当前时间戳
       * @return <int>    unix时间戳(秒) 
       */
      CurTime: function(){
        return Date.parse(new Date())/1000;
      },
      /**       
       * 日期 转换为 Unix时间戳
       * @param <string> 2014-01-01 20:20:20 日期格式       
       * @return <int>    unix时间戳(秒)       
       */
      DateToUnix: function(string) {
        var f = string.split(' ', 2);
        var d = (f[0] ? f[0] : '').split('-', 3);
        var t = (f[1] ? f[1] : '').split(':', 3);
        return (new Date(
            parseInt(d[0], 10) || null,
            (parseInt(d[1], 10) || 1) - 1,
            parseInt(d[2], 10) || null,
            parseInt(t[0], 10) || null,
            parseInt(t[1], 10) || null,
            parseInt(t[2], 10) || null
            )).getTime() / 1000;
      },
      /**       
       * 时间戳转换日期       
       * @param <int> unixTime  待时间戳(秒)       
       * @param <bool> isFull  返回完整时间(Y-m-d 或者 Y-m-d H:i:s)       
       * @param <int> timeZone  时区       
       */
      UnixToDate: function(unixTime, isFull, timeZone) {
        if (typeof (timeZone) == 'number')
        {
          unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
        }
        var time = new Date(unixTime * 1000);
        var ymdhis = "";
        ymdhis += (time.getUTCFullYear()<10?'0'+time.getUTCFullYear():time.getUTCFullYear() )+ "-";
        ymdhis += ((time.getUTCMonth()+1)<10?'0'+(time.getUTCMonth()+1):(time.getUTCMonth()+1) )+ "-";
        ymdhis += (time.getUTCDate()<10?'0'+time.getUTCDate(): time.getUTCDate());
        if (isFull === true)
        {
          ymdhis += " " + (time.getUTCHours()<10?'0'+time.getUTCHours():time.getUTCHours()) + ":";
          ymdhis += (time.getUTCMinutes()<10?'0'+time.getUTCMinutes():time.getUTCMinutes()) + ":";
          ymdhis += (time.getUTCSeconds()<10?'0'+time.getUTCSeconds():time.getUTCSeconds());
        }
        return ymdhis;
      }
    }
  });
})(jQuery);
</script>